package make.money;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import make.money.gold.ListUtils;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class xinlangBool {
    public static void main(String[] args) throws Exception{
        List<String> xinlangs = bool.readFile("D:\\xinlang.txt");
        xinlangs = xinlangs.stream().distinct().collect(Collectors.toList());
        List<String> maneys = new ArrayList<>();
        if(CollUtil.isNotEmpty(xinlangs)){
            for(String s : xinlangs){
                if(StrUtil.isBlank(s)){
                    continue;
                }
                String [] a = s.split("\\|");
                for(String c : a){
                    if(c.length()>3){
                        String [] b  =c.split(",");
                        if(Integer.parseInt(b[0])>100){
                            b[0]=b[0].substring(2,b[0].length());
                        }
                        Boolean flag = bool.whereMoney(Arrays.asList(Integer.parseInt(b[0]),
                                Integer.parseInt(b[1]),
                                Integer.parseInt(b[2]),
                                Integer.parseInt(b[3]),
                                Integer.parseInt(b[4]),
                                Integer.parseInt(b[5])));
                        if(flag){
                            maneys.add(b[0]+","+b[1]+","+b[2]+","+b[3]+","+b[4]+","+b[5]);
                        }
                    }
                }

            }
        }

        maneys = getMoney(4,maneys);
        if(CollUtil.isEmpty(maneys)){return ;}
        Thread.sleep(1000);
        System.out.println("中奖："+maneys.size());

        BufferedWriter bu = null;
        try {
            File file = new File(bool.filePath);
            bu = new BufferedWriter(new FileWriter(file, true));
            for(String maney : maneys){
                bu.newLine();
                bu.write(maney);

            }

        }catch (Exception e){

        }finally {
            if (bu != null) {
                bu.close();
            }
        }

        Thread.sleep(1000);
        bool.sortFile(bool.filePath);
    }


    /**
     * 获取结果
     */
    private static List<String> getMoney(int togetCount,List<String> money) throws Exception{
        //获取随机数


        //读取文件
        List<String> fileYun = bool.readFile(bool.filePath);
//        List<String> moneyYun = bool.readFile(filePathMoney);

        // 获取随机结果
//        List<String> suijiYun = ListUtils.getSuijiYun(suijiResult,fileYun);
//        suijiYun = getsuijiList(suijiYun,togetCount); // 自身便利排除4个一样的
        // 遍历集合2 判断有没有相同数 有就不存
        List<String> makeMoney = bool.getMoneyYun(fileYun,money,togetCount);
        // 存入文件中
        if(CollUtil.isNotEmpty(money) ){
            return makeMoney;
        }else{
            return null;
        }



    }

}
